namespace NBody.Analysis
{
    using System;
    using DataFile;
     
    public class VelocityBin : Bin
    {
        public enum Direction { Radial, Theta, Phi, Tangential };
        
        protected Direction direction = Direction.Radial;
        
        public Direction VelocityDirection
        {
            get { return direction; }
            set { direction = value; }
        }
        
        public override void Analyse(NBodySystem s)
        {
            Function f;
            switch (direction)
            {
                case Direction.Radial:
                    f = new Function(vr);
                    break;
                case Direction.Theta:
                    f = new Function(vt);
                    break;
                case Direction.Phi:
                    f = new Function(vp);
                    break;
                case Direction.Tangential:
                    f = new Function(vtan);
                    break;
                default:
                    f = new Function(vr);
                    break;
            }
            
            switch (spacing)
            {
                case Spacing.Normal:
                    radial_bin_normal(s, f);
                    break;
                case Spacing.Logarithmic:
                    radial_bin_log(s, f);
                    break;
                case Spacing.EqualMass:
                    radial_bin_equal_mass(s, f);
                    break;
            }
        }
        
        private double vr(Particle p)
        {
            return Math.Sqrt(p.RadialVelocity * p.RadialVelocity);
        }
        
        private double vt(Particle p)
        {
            return p.ThetaVelocity;
        }
        
        private double vp(Particle p)
        {
            return p.PhiVelocity;
        }
        
        private double vtan(Particle p)
        {
            return p.TangentialVelocity;
        }
    }
}           
